/*PROGRAM
		GETD92 - GET A DECIMAL NUMBER.
  PROGRAMMER
		ROBERT M. WHITE
  DATE WRITTEN
		APRIL 10, 1981
  PURPOSE
		THIS ROUTINE GETS A DECIMAL NUMBER FROM
		THE TERMINAL OPERATOR, CONVERTS IT TO
		INTERNAL FORM, AND VALIDATES IT.  CONTROL
		IS RETURNED ONLY WHEN A VALID NUMBER HAS
		BEEN ENTERED.
  INPUT
		13-BYTE 9-DIGIT NUMBER W/2-DECIMAL PLACES
  OUTPUT
		5-BYTE 9-DIGIT NUMBER W/2-DECIMAL PLACES (PACKED)
  RETURN CODES
		0=SUCCESSFUL COMPLETION
  REMARKS
		1. ALLOW 13 BYTES ON THE SCREEN FOR THE NUMBER.
*/

GETD92: PROC (X,Y,NUM,LO,HI,RTN_COD);
	DCL	X BIN(7), /* ROW */
		Y BIN(7), /* COLUMN */
		NUM DEC(9,2), /* RETURNED NUMBER */
		LO DEC(9,2), /* LOW RANGE CHECK */
		HI DEC(9,2), /* HIGH RANGE CHECK */
		RTN_COD BIN(7); /* RETURN CODE */

	DCL	V CHAR(13);
	DCL	VW CHAR(13) VARYING;

	DCL	GETSTR ENTRY(BIN(7),BIN(7),BIN(7),PTR,BIN(7));
	DCL	PUTERR ENTRY(CHAR(80) VARYING);
	DCL	PUTD92 ENTRY(BIN(7),BIN(7),PTR);

/* GET THE NUMBER. */
	ON ERROR		/* HANDLE CONVERSION ERRORS. */
	   BEGIN;
	     GOTO CONV_ERROR;
	   END;
	ON FIXEDOVERFLOW	/* HANDLE CONVERSION ERRORS. */
	   BEGIN;
	     GOTO CONV_ERROR;
	   END;
START:
	CALL GETSTR(X,Y,LENGTH(V),ADDR(V),RTN_COD); /* GET IT. */
	VW=V;
	DO WHILE(SUBSTR(VW,LENGTH(VW),1)=' '); /* REMOVE TRAILING BLANKS. */
	   VW=SUBSTR(VW,1,LENGTH(VW)-1);
	END;

/* VALIDATE THE NUMBER. */
	NUM = DEC(VW,9,2);
	IF LO=0 & HI=0 THEN  /* DON'T RANGE CHECK. */
	   ;
	ELSE
	   IF NUM<LO | NUM>HI THEN
	     DO;
	       SIGNAL ERROR(1);
	     END;

/* REWRITE DATA ON SCREEN TO CLEAN IT UP. */
	CALL	PUTD92(X,Y,ADDR(NUM));
	RETURN;

/* HANDLE ERROR CONDITIONS. */
CONV_ERROR:
	CALL PUTERR('*** INVALID NUMBER ***');
	GOTO START;

/* RETURN TO CALLER. */
	END	GETD92;

